package com.lyx.user.controller;

import com.lyx.common.result.R;
import com.lyx.common.result.Result;
import com.lyx.common.result.ResultUtil;
import com.lyx.common.to.UserTo;
import com.lyx.common.utils.JwtUtils;
import com.lyx.user.entity.User;
import com.lyx.user.service.UserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 获取用户信息
 * @author 14667
 * @date 2022/7/19 18:50
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    /**
     * 获取用户信息
     * @param request
     * @return
     */
    @GetMapping("/userInfo")
    public R getUserInfo(HttpServletRequest request){
        User user  = userService.getUserInfo(request);
        return R.ok().data("data",user);
    }

    @GetMapping("/userInfoById")
    public R getUserInfoById(@RequestParam Integer userId){
        User user  = userService.getUserById(userId);
        return R.ok().data("data",user);
    }

    /**
     * 根据ids获取用户信息集合
     * @param ids
     * @return
     */
    @GetMapping("/users")
    public R getUsers(@RequestParam List<Integer> ids){
        List<UserTo> users = userService.getUsers(ids);
        return R.ok().data("data",users);
    }
}
